﻿using A.M.ETO;
using DotNetCore.CAP;
using L.M.System.Application.IServices;
using L.M.System.Domain.DTO;
using L.M.System.Domain.Entity;
using L.M.System.Infrastruecure.Repository;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace L.M.System.Read.API.Controllers
{
    /// <summary>
    /// 组织架构
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class Organization_chartReadController : ControllerBase
    {
        private readonly IOrganization_chartServices organization_ChartServices;
        public Organization_chartReadController(IOrganization_chartServices organization_ChartServices)
        {
            this.organization_ChartServices = organization_ChartServices;
        }


        /// <summary>
        /// 递归显示组织架构
        /// </summary>
        /// <param name="oId">主编号</param>
        /// <returns>递归显示组织架构</returns>
        [HttpGet]
        public IActionResult GetOrgainInforShow(string? oName, string? oId = "ZJ00000000001")
        {
            ApiReturn<DepMinrInforDTO> apiReturn = new ApiReturn<DepMinrInforDTO>();
            var list =  organization_ChartServices.GetOrgainInforShow(oName,oId);
            apiReturn.Code = 200;
            apiReturn.Message = "成功";
            apiReturn.ListInfor = list;
            return Ok(apiReturn);
        }

        /// <summary>
        /// 组织架构添加
        /// </summary>
        /// <param name="organiAddDTO">对象</param>
        /// <returns>统一返回格式</returns>
        [HttpPost]
        public async Task<IActionResult> PostAddOrgainInfor(OrganiAddDTO organiAddDTO)
        {
            if(organiAddDTO.department_fid == "" || organiAddDTO.department_fid == null)
            {
                organiAddDTO.department_fid = "ZJ00000000001";
            }
            var res= await organization_ChartServices.PostAddOrgainInfor(organiAddDTO);
            return Ok(res);
        }

        /// <summary>
        /// 部门删除
        /// </summary>
        /// <param name="oId">部门编号</param>
        /// <returns>统一返回格式</returns>
        [HttpDelete]
        public async Task<IActionResult> DelPostInfor(string? oId)
        {
            return Ok(await organization_ChartServices.DelPostInfor(oId));
        }

        /// <summary>
        /// 反填部门
        /// </summary>
        /// <param name="oId">编号</param>
        /// <returns>统一返回格式</returns>
        [HttpGet]
        public async Task<IActionResult> FanInforOrm(string? oId)
        {
            return Ok(await organization_ChartServices.FanInforOrm(oId));
        }


        /// <summary>
        /// 组织架构修改
        /// </summary>
        /// <param name="organiAddDTO">对象</param>
        /// <returns>统一返回格式</returns>
        [HttpPut]
        public async Task<IActionResult> PostUpdOrgainInfor(OrganiAddDTO organiAddDTO)
        {
            return Ok(await organization_ChartServices.PostUpdOrgainInfor(organiAddDTO));
        }


    }
}
